#include "..\..\..\..\platform\include\imp_typedefine.h"
#include "..\..\..\..\platform\include\imp_io_wrapper.h"
#include "..\..\..\..\platform\include\imp_os_wrapper.h"
#include "..\..\..\..\platform\include\imp_syspara_wrapper.h"
#include "..\..\..\..\platform\include\imp_pictext_wrapper.h"
#include "..\..\..\..\platform\include\imp_vui_wrapper.h"

#include "..\..\..\..\platform\spreadtrum\adapter\mbm_sys_adapter.h"
#include "..\..\..\..\platform\spreadtrum\adapter\mbm_vui_adapter.h"

#include "..\..\..\AppManager\lib\inc\imiam_module.h"

#include "imibase.h"
#include "imibase_verno.h"

const char *g_imibase_date = __DATE__;


static Int32 g_imiam_obj = 0;


extern "C" Int32 imiam_get_root_ext(void);
extern "C" void imiam_set_root_ext(Int32 hdl);
extern "C" void imebill_sms_module_init(void);

Int32 imiam_get_root_ext(void)
{
	return g_imiam_obj;
}
void imiam_set_root_ext(Int32 hdl)
{
	g_imiam_obj = hdl;
}

static void ImiAM_Function(Int32 id, void* param)
{
	IMP_Trace("ImiAM_Function id=%d", id);
	switch(id)
	{
	case IMIAM_Notify_exit:
		mbm_send_signal(0, SIG_MBM_EXIT_AM, 0, 0);
		break;
	default:
		break;
	}
}
void imibase_startup(ImpCStr appid, const void *invite)
{
	Int8* screen_frame = NULL;
	UInt32 buf_size = 0;
	Int32 update_num=0;
	ImpCStr app_url, entry_param;
	ImpCStr *update_info=0;

	screen_frame = mbm_GetLCDFrameBuffer(&buf_size);

	if(!mbm_get_startup_url(appid, &update_num, &update_info, &app_url, &entry_param))
		return;
	IMP_Trace("imibase_startup: appid=%s, app_url=%s, entry_param=%s\n", appid, app_url, entry_param);
	for(Int32 i=0; i<update_num; i++)
		IMP_Trace("update_info[%d]=%s\n", i, update_info[i]);
	
	imebill_sms_module_init();
	imiam_open(appid, 
		app_url, entry_param,
		update_num, update_info,		
		screen_frame, impict_get_screen_width(), impict_get_screen_height(), 
		ImiAM_Function, invite);
}

void imibase_setting(void)
{
	Int8* screen_frame = NULL;
	UInt32 buf_size = 0;

	screen_frame = mbm_GetLCDFrameBuffer(&buf_size);
	imiam_setting(
		screen_frame, impict_get_screen_width(), impict_get_screen_height(), 
		ImiAM_Function);
}

void imibase_exit(void)
{
	imiam_close();
}

